package service;

import dao.goodsDao;

import java.util.Scanner;

public class goodsService {
    public goodsDao dao = new goodsDao();

    public void goodsServiceUI() {
        boolean flag = true;
        while (flag) {
            System.out.println("--------商品管理系统--------");
            System.out.println("|\t1. 商品列表\t\t");
            System.out.println("|\t2. 添加商品\t\t");
            System.out.println("|\t3. 查找商品\t\t");
            System.out.println("|\t4. 修改商品属性\t\t");
            System.out.println("|\t5. 删除商品\t\t");
            System.out.println("|\t6. 设置促销商品\t\t");
            System.out.println("|\t7. 退出商品管理系统\t\t");
            System.out.println("-------------------------");
            Scanner sc = new Scanner(System.in);
            int inputNo = sc.nextInt();
            switch (inputNo) {
                case 1:
                    dao.listGoodsData();
                    break;
                case 2:
                    System.out.println("输入商品ID");
                    int id = sc.nextInt();
                    System.out.println("输入商品名称");
                    String name = sc.next();
                    System.out.println("输入商品价格");
                    float price = sc.nextFloat();
                    if (dao.addGoods(id, name, price)) {
                        System.out.println("商品添加成功");
                    }else {
                        System.out.println("商品添加失败，请重新输入编号");
                    }
                    break;
                case 3:

                    if (!dao.checkGoods()) {
                        System.out.println("无此商品");
                    }
                    break;
                case 4:
                    if (!dao.setGoodsAttribute()) {
                        System.out.println("系统错误，请重新操作");
                    }
                    break;
                case 5:
                    System.out.println("请输入要删除的商品名称");
                    String delName = sc.next();
                    if (!dao.delGoods(delName)) {
                        System.out.println("此商品不存在");
                    }
                    break;
                case 6:
                    System.out.println("输入商品编号");
                    int num = sc.nextInt();
                    System.out.println("输入打折力度(0,1)");
                    float  discount = sc.nextFloat();
                    if(!dao.setDiscount(num, discount)) {
                        System.out.println("编号错误");
                    } else {
                        System.out.println("设置成功");
                    }
                    break;
                case 7:
                    flag = false;
                    break;
                default:
                    System.out.println("请输入数字1-5");
            }
        }
    }
}
